import 'package:boss/ui/page/commodity/bindingCommodity/provider/binding_commodity_provider.dart';
import 'package:boss/ui/widget/custom_list_title.dart';
import 'package:boss/ui/widget/label_button.dart';
import 'package:boss/ui/widget/search_bar.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class UnBoundList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.symmetric(
              horizontal: 30.w,
              vertical: 15.w,
            ),
            child: SearchBar(
              hintText: '菜品名',
              onChanged: (value) {
                var provider = Provider.of<BindingCommodityProvider>(
                  context,
                  listen: false,
                );
                provider.setSearchWord(value);
              },
            ),
          ),
          Expanded(
            child: Consumer<BindingCommodityProvider>(
              builder: (context, provider, _) => ListView.builder(
                padding: EdgeInsets.symmetric(
                  horizontal: 30.w,
                ),
                itemBuilder: (context, index) {
                  var current = provider.commoditys[index];

                  return CustomListTitle(
                    title: current.title,
                    trailing: LabelButton(
                      title: '立即关联',
                      onTap: () {
                        provider.binding(current);
                      },
                    ),
                  );
                },
                itemCount: provider.commoditys.length,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
